<template>
    <div class="block">
        <el-row class="block-item">
            <!-- <template v-if="!isLogin">
                帐号: <el-input style="width:140px" v-model="base.userId" clearable/>
                密码: <el-input style="width:100px" type="password" v-model="base.password" clearable/>
                随机数: <el-input style="width:100px" v-model="base.identifyCode" clearable/>
                <el-image :src="'https://jy.xzsec.com/Login/YZM?randNum='+base.randomNum" @click="reRandom" style="vertical-align:bottom;width:95px;"></el-image>
                
                <el-button type="success" @click="login">登录</el-button>
            </template> -->
            <template >
                <el-button type="primary" @click="startQuery">开始</el-button>
                
                <el-button type="text" @click="openLoginPage" class="ml20" style="float:right">打开登录页面</el-button>
                <el-button type="text" @click="openInfoPage" class="ml20" style="float:right">打开链接页面</el-button>
                <el-button type="text" @click="clearAll" class="ml20" style="float:right">清空</el-button>

                <el-popover  placement="bottom" width="250" trigger="hover">
                    <el-form size="mini" label-width="90px" class="mini-form" style="text-align:right">
                        <el-form-item label="帐号"> {{base.userId}} </el-form-item>
                        <el-form-item label="投入"> {{monInfo.preTotal | bigMoneyFormat}}  (+{{otherMon | bigMoneyFormat}}) </el-form-item>
                        <el-form-item label="当前总资产"> {{monInfo.total | bigMoneyFormat}} </el-form-item>
                        <el-form-item label="总市值"> {{bigMoneyFixFormat(null,null,monInfo.stockVal)}}</el-form-item>
                        <el-form-item label="资金余额"> {{bigMoneyFixFormat(null,null,monInfo.total - monInfo.stockVal)}} </el-form-item>
                        <el-form-item label="实际盈亏"> {{bigMoneyFixFormat(null,null,monInfo.total - monInfo.preTotal )}} </el-form-item>
                        <el-form-item label="持仓比例"> {{monInfo.stockVal*100 /monInfo.total | fixed2}}% </el-form-item>
                        <el-form-item label="新股" v-if="newStockInfo">
                            <div v-if="newStockInfo.list">
                                <el-row v-for="(item,idx) in newStockInfo.list" :key="idx" >
                                    <el-button size="mini" type="text" class="red" @click="buyNewStock(item)">{{item[1]}}-{{item[2]}}</el-button>
                                </el-row>
                            </div>
                        </el-form-item>
                    </el-form>
                    <el-button slot="reference" type="text" class="ml20" :class="(newStockInfo && newStockInfo.list.length>0)?'red':''" style="float:right">帐号信息</el-button>
                </el-popover>
                <el-button type="text" class="ml20" style="float:right">

                    <span v-for="(item,idx) in jjList" :key="idx" class="ml20">
                        <el-link target="_blank" :href="'http://fund.eastmoney.com/'+item.code+'.html?spm=search'">
                            {{item.name}}
                            :
                            <span :class="getRateColor(item.rate)">{{item.rate}}</span>
                        </el-link>
                    </span>

                </el-button>
            </template>
        </el-row>
        <el-row  class="block-item">
            <el-col :span="11">
                
                <el-table :data="topList" style="width: 100%" max-height="300" size="mini"  highlight-current-row class="small-table-class"
                :row-class-name="getRowClass"
                @row-click="handleSelectionChange">
                    <el-table-column label="持仓" width="100" align="center"> 
                        <el-table-column prop="stock" label="名称" width="120" align="center" sortable :filters="buyHisList" :filter-method="filterDetailList">
                            <template slot-scope="s">
                                {{s.row.stock+'-'+s.row.name}}
                            </template>
                        </el-table-column>
                        <el-table-column prop="buyDate" label="买入日期" width="120" sortable :formatter="dateFormater"></el-table-column>
                        <el-table-column prop="buyPrice" label="买入价格" width="75"></el-table-column>
                        <el-table-column prop="basePrice" label="基准价格" width="75"></el-table-column>
                        <el-table-column prop="nextSale" label="卖出价格" width="70">
                            <template slot-scope="s">
                                <span v-if="s.row.lastPrice && s.row.nextSale<=s.row.lastPrice">
                                    <span class="red" @dblclick.stop="tradeStock(s.row.stock,s.row.buyAmount,'S',s.row.nextSale,s.row.name)">{{s.row.nextSale | fixed2}}</span>
                                </span>
                                <span v-else class="tips-darkblue" @dblclick.stop="tradeStock(s.row.stock,s.row.buyAmount,'S',s.row.nextSale,s.row.name)" style="font-size:12px">{{s.row.nextSale | fixed2}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="lastRate" label="最新价格" width="115" sortable>
                            <template slot-scope="s">
                                <span v-if="s.row.lastPrice" :class="getColor(s.row.lastPrice,s.row.buyPrice)">
                                    {{s.row.lastPrice.toFixed(2)}}
                                    ({{s.row.lastRate.toFixed(2)}}%)
                                </span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="buyAmount" label="数量" width="55"></el-table-column>
                        <el-table-column prop="buyTotalPrice" label="买入金额"></el-table-column>
                        <!-- <el-table-column prop="nextBuy" label="买入价格">
                            <template slot-scope="s">
                                <span class="green" @dblclick.stop="tradeStock(s.row.stock,s.row.buyAmount,'B',s.row.nextBuy,s.row.name)">{{s.row.nextBuy | fixed2}}</span>
                            </template>
                        </el-table-column> -->
                    </el-table-column>
                </el-table>
            </el-col>
            <el-col :span="1.6" style="text-align:center;border-right:1px dotted gray;height:100%;padding:0px 10px;max-height:320px">
                <el-row>价格列表</el-row>
                <template v-if="stepCfg[tradeInfo.code]">
                    <el-row v-for="(item,idx) in stepCfg[tradeInfo.code].stepList" :key="idx">
                        <el-link v-if="stepCfg[tradeInfo.code].buycount>=(idx+1)" type="info">{{item}}</el-link>
                        <el-link v-else-if="stepCfg[tradeInfo.code].buycount==(idx)" type="warning">{{item}}</el-link>
                        <el-link v-else type="primary" @click="selPrice(item)">{{item}}</el-link>
                    </el-row>
                </template>
            </el-col>
            <el-col :span="3.7" style="border-right:1px dotted gray;padding:0px 10px">
                <el-row class="mt10">
                    &nbsp;&nbsp;自动查询&nbsp;&nbsp;<el-switch v-model="aotoQry" @change="setTimer"></el-switch>
                    间隔: <el-input v-model="sleepTime" style="width:60px" size="mini"></el-input>
                </el-row>
                <el-row class="mt10">
                    &nbsp;&nbsp;查看代码: <el-input v-model="tradeInfo.code" style="width:150px" size="mini"></el-input>
                </el-row>
                <el-row class="mt10">
                    &nbsp;&nbsp;股票名称: <span v-if="selData">{{selData.name}}</span>
                </el-row>
                <el-row class="mt10">
                    &nbsp;&nbsp;交易类型: <el-radio-group v-model="tradeInfo.type">
                        <el-radio label="B">买入</el-radio>
                        <el-radio label="S">卖出</el-radio>
                    </el-radio-group>
                    
                </el-row>
                <el-row class="mt10">
                    &nbsp;&nbsp;交易数量: <el-input-number v-model="tradeInfo.amount" :step="100" style="width:150px" size="mini"></el-input-number>
                </el-row>
                <el-row class="mt10">
                    &nbsp;&nbsp;交易价格: <el-input-number v-model="tradeInfo.price" :step="0.01" style="width:150px" size="mini"></el-input-number>
                </el-row>
                <el-row class="mt10">
                    &nbsp;&nbsp;交易金额: {{tradeInfo.amount * tradeInfo.price | fixed}} ( {{monInfo.total - monInfo.stockVal | fixed2}} )
                </el-row>
                <el-row class="mt10" style="text-align:center">
                    <el-button size="mini" type="primary" @click="goTrade">提交</el-button>
                    <el-button size="mini" type="primary" @click="getStep5Price">查询</el-button>
                </el-row>

            </el-col>
            <el-col :span="3" style="text-align:center;border-right:1px dotted gray;padding:0px 1px;">
                <el-row v-if="!selData.code">
                    5档成交数据
                </el-row>
                <el-row>{{selData.name}}&nbsp;{{selData.code}}
                     <!-- (
                    <span :class="getColor(selData.bottomprice,selData.fivequote.yesClosePrice)">{{selData.bottomprice}}</span>
                    -
                    <span :class="getColor(selData.topprice,selData.fivequote.yesClosePrice)">{{selData.topprice}}</span>
                    ) -->
                </el-row>
                <template v-if="selData.name">

                    <el-row v-for="(item) in [5,4,3,2,1]" :key="item+100">
                        <span @click="selPrice(selData.fivequote['sale'+item])">
                        <el-col :span="8">卖{{item}}</el-col>
                        <el-col :span="8" :class="getColor(selData.fivequote['sale'+item],selData.fivequote.yesClosePrice)">{{selData.fivequote["sale"+item]}}</el-col>
                        <el-col :span="8" :class="getColor(selData.fivequote['sale'+item],selData.fivequote.yesClosePrice)">{{selData.fivequote["sale"+item+"_count"]}}</el-col>
                        </span>
                    </el-row>
                    <el-row>&nbsp;</el-row>
                    <el-row v-for="(item) in [1,2,3,4,5]" :key="item">
                        <span @click="selPrice(selData.fivequote['buy'+item])">
                        <el-col :span="8">买{{item}}</el-col>
                        <el-col :span="8" :class="getColor(selData.fivequote['buy'+item],selData.fivequote.yesClosePrice)">{{selData.fivequote["buy"+item]}}</el-col>
                        <el-col :span="8" :class="getColor(selData.fivequote['buy'+item],selData.fivequote.yesClosePrice)">{{selData.fivequote["buy"+item+"_count"]}}</el-col>
                        </span>
                    </el-row>
                    <el-row>&nbsp;</el-row>
                    <el-row :class="getColor(selData.realtimequote.currentPrice,selData.fivequote.yesClosePrice)">
                        <el-col :span="8">当前</el-col>
                        <el-col :span="8">{{selData.realtimequote.currentPrice}}</el-col>
                        <el-col :span="8">{{priceRate(selData.realtimequote.currentPrice,selData.fivequote.yesClosePrice)}}</el-col>
                    </el-row>
                    <el-row :class="getColor(selData.realtimequote.high,selData.fivequote.yesClosePrice)">
                        <el-col :span="8">最高</el-col>
                        <el-col :span="8">{{selData.realtimequote.high}}</el-col>
                        <el-col :span="8">{{priceRate(selData.realtimequote.high,selData.fivequote.yesClosePrice)}}</el-col>
                    </el-row>
                    <el-row :class="getColor(selData.realtimequote.low,selData.fivequote.yesClosePrice)">
                        <el-col :span="8">最低</el-col>
                        <el-col :span="8">{{selData.realtimequote.low}}</el-col>
                        <el-col :span="8">{{priceRate(selData.realtimequote.low,selData.fivequote.yesClosePrice)}}</el-col>
                    </el-row>
                    <el-row :class="getColor(selData.realtimequote.open,selData.fivequote.yesClosePrice)">
                        <el-col :span="8">开盘</el-col>
                        <el-col :span="8">{{selData.realtimequote.open}}</el-col>
                        <el-col :span="8">{{priceRate(selData.realtimequote.open,selData.fivequote.yesClosePrice)}}</el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <span class="red" @click="selPrice(selData.realtimequote.zt)">
                                涨停: {{selData.realtimequote.zt}}
                            </span>
                        </el-col>
                        <el-col :span="12">
                            <span class="green" @click="selPrice(selData.realtimequote.dt)">
                                跌停: {{selData.realtimequote.dt}}
                            </span>
                        </el-col>
                    </el-row>

                </template>
            </el-col>
            <el-col :span="2.5" style="text-align:left;border-right:1px dotted gray;height:100%;padding:0px 10px;overflow-y:hidden;max-height:320px">
                <el-row style="text-align:center">明细-{{selData.name}}</el-row>
                <template v-if="selData.name">
                <el-row v-for="(item,idx) in tradeInfo.detailList" :key="idx" class="mt5">
                    <span >{{item[0]}}  </span>
                    <span  :class="getColor(item[1],selData.fivequote.yesClosePrice)">{{item[1]}}  </span>
                    <span :class="item[3]==1?'green':'red'">{{item[2]}}</span>
                </el-row>
                </template>
            </el-col>
            <el-col :span="3" style="text-align:center;border-right:1px dotted gray;height:100%;padding:0px 10px;overflow-y:hidden;max-height:320px">
                <el-row>关注列表</el-row>
                <el-row v-for="(item,idx) in favList" :key="idx" class="mt5">
                    <el-link type="primary" @click="handleSelectionChange(item.c)">
                        <span class="span-name" :class="getRateColor(item.r)">{{item.n}}</span>
                        <span class="span-price" :class="getRateColor(item.r)">{{item.p}}</span>
                        <span class="span-rate" :class="getRateColor(item.r)">{{item.r}}%</span>
                    </el-link>
                </el-row>
            </el-col>

            
        </el-row>
        <el-row  class="block-item">
            <el-col :span="13">
                <exTable :data="storeList" style="width: 100%" maxHeight="300" size="mini" @row-click="handleSelectionChange"
                    :show-summary="true" :fit="true"
                 :default-sort="{prop:'Zxsz',order:'descending'}">
                    <el-table-column label="持仓" width="250" align="center"> 
                        <el-table-column prop="Zqdm" label="证券代码" width="115">
                            <template slot-scope="s">
                                {{s.row.Zqdm}}-{{s.row.Zqmc}}
                            </template>
                        </el-table-column>
                        <!-- <el-table-column prop="Zqmc" label="证券名称" width="75"></el-table-column> -->
                        <el-table-column prop="Zqsl" label="持仓" width="55" align="right"></el-table-column>
                        <el-table-column prop="Kysl" label="可用" width="55" align="right"></el-table-column>
                        <el-table-column prop="Cbjg" label="成本价" width="65" align="right"></el-table-column>
                        <el-table-column prop="Zxsz" label="最新市值" width="85" align="right"></el-table-column>
                        <el-table-column prop="Ljyk" label="总盈亏" width="85" align="right" sortable>
                            <template slot-scope="s">
                                <span :class="getRateColor(s.row.Ljyk)">{{s.row.Ljyk}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="Ykbl" label="总比例" width="85" align="right" sortable>
                            <template slot-scope="s">
                                <span :class="getRateColor(s.row.Ykbl)">{{s.row.Ykbl}}</span>
                            </template>
                        </el-table-column>
                    </el-table-column>
                    <el-table-column label="今日" width="150" align="center"> 
                        <el-table-column prop="Zxjg" label="当前价" width="65" align="right"></el-table-column>
                        <el-table-column prop="diff" label="幅度" width="65" align="right">
                            <template slot-scope="s">
                                <span v-if="s.row.diff" :class="getRateColor(s.row.diff)">{{s.row.diff}}</span>
                            </template>
                        </el-table-column>
                        <exColumn prop="wave" label="比例" width="65" align="right" >
                            <template slot-scope="s">
                                <span v-if="s.row.wave" :class="getRateColor(s.row.wave)">{{s.row.wave}}</span>
                            </template>
                        </exColumn>
                        <el-table-column prop="jryk" label="盈亏" width="75"  align="right" sortable>
                            <template slot-scope="s">
                                <span v-if="s.row.jryk" :class="getRateColor(s.row.jryk)">{{s.row.jryk}}</span>
                            </template>
                        </el-table-column>
                    </el-table-column>
                    <exColumn min-width="10"></exColumn>
                </exTable>
            </el-col>
            <el-col :span="11">
                <el-table :data="revokeList" style="width: 100%" height="290" size="mini">
                    <el-table-column label="撤单列表" width="150" align="center"> 
                        <el-table-column prop="Wtsj" label="委托时间" width="75"></el-table-column>
                        <el-table-column prop="Zqdm" label="证券代码" width="75"></el-table-column>
                        <el-table-column prop="Zqmc" label="证券名称" width="75"></el-table-column>
                        <el-table-column prop="Mmsm" label="委托方向" width="75"></el-table-column>
                        <el-table-column prop="Wtzt" label="委托状态" width="75"></el-table-column>
                        <el-table-column prop="Wtsl" label="委托数量" width="75" align="right"></el-table-column>
                        <el-table-column prop="Wtjg" label="委托价格" width="75" align="right"></el-table-column>
                        <el-table-column label="金额" width="75" align="right">
                            <template slot-scope="scope">
                                {{(scope.row.Wtsl * scope.row.Wtjg).toFixed(0)}}
                            </template>
                        </el-table-column>
                        <el-table-column prop="Wtbh" label="委托编号" width="75"></el-table-column>
                        <el-table-column prop="oper" label="操作" >
                            <template slot-scope="scope">
                                <el-button type="primary" size="mini" @click="revokeOrder(scope.row)">撤</el-button>
                            </template>
                        </el-table-column>
                    </el-table-column>
                </el-table>
            </el-col>
        </el-row>
        <el-row  class="block-item">
            <el-col :span="12">
                <el-table :data="hisList" style="width: 100%" height="300" size="mini">
                    <el-table-column label="历史成交" width="150" align="center"> 
                        <el-table-column prop="Cjrq" label="成交日期" width="75"></el-table-column>
                        <el-table-column prop="Cjsj" label="成交时间" width="75"></el-table-column>
                        <el-table-column prop="Zqdm" label="证券代码" width="75"></el-table-column>
                        <el-table-column prop="Zqmc" label="证券名称" width="75"></el-table-column>
                        <el-table-column prop="Mmsm" label="委托方向" width="75"></el-table-column>
                        <el-table-column prop="Cjsl" label="成交数量" width="75" align="right"></el-table-column>
                        <el-table-column prop="Cjjg" label="成交价格" width="75" align="right"></el-table-column>
                        <el-table-column prop="Cjje" label="成交金额" width="75" align="right"></el-table-column>
                        <el-table-column prop="Cjbh" label="编号" width="130" align="right"></el-table-column>
                        <el-table-column prop="date" label="费用" align="right">
                            <template slot-scope="scope">
                                {{scope.row.totalFee | fixed2}}
                            </template>
                        </el-table-column>
                        <!-- 佣金	交易规费	印花税	过户费	 -->
                    </el-table-column>

                </el-table>
            </el-col>
            <el-col :span="12">
                <el-table :data="todayList" style="width: 100%" height="300" size="mini">
                    <el-table-column label="今日成交" width="150" align="center"> 
                        <el-table-column prop="Cjrq" label="成交日期" width="75"></el-table-column>
                        <el-table-column prop="Cjsj" label="成交时间" width="75"></el-table-column>
                        <el-table-column prop="Zqdm" label="证券代码" width="75"></el-table-column>
                        <el-table-column prop="Zqmc" label="证券名称" width="75"></el-table-column>
                        <el-table-column prop="Mmsm" label="委托方向" width="75"></el-table-column>
                        <el-table-column prop="Cjsl" label="成交数量" width="75" align="right"></el-table-column>
                        <el-table-column prop="Cjjg" label="成交价格" width="75" align="right"></el-table-column>
                        <el-table-column prop="saleprice" label="预售价额" width="75" align="right">
                            <template slot-scope="s">
                                <span class="red" v-if="s.row.Mmsm.indexOf('买入')!=-1">{{(s.row.Cjjg*1.03).toFixed(2)}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="Cjje" label="成交金额" width="75" align="right"></el-table-column>
                        <el-table-column prop="Wtbh" label="编号" width="" align="right"></el-table-column>

                        
                    </el-table-column>

                </el-table>
            </el-col>
        </el-row>
        <el-row  class="block-item">
            <el-table :data="detailList" style="width: 100%" max-height="600" size="mini"
                :summary-method="getSummaries"
                :show-summary="true">
                <el-table-column label="利润计算" width="150" align="center"> 
                    <el-table-column prop="stock" label="名称" width="160" align="center" sortable :filters="buyHisList" :filter-method="filterDetailList">
                        <template slot-scope="s">
                            {{s.row.stock+'-'+s.row.name}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="buyDate" label="买入日期" width="140" sortable :formatter="dateFormater"></el-table-column>
                    <el-table-column prop="buyPrice" label="买入价格" width="110" sortable></el-table-column>
                    <el-table-column prop="buyAmount" label="买入数量" width="110" sortable></el-table-column>
                    <el-table-column prop="buyTotalPrice" label="买入金额" width="110" sortable></el-table-column>
                    <el-table-column prop="salePrice" label="卖出价格" width="110" sortable></el-table-column>
                    <el-table-column prop="rate" label="点数" width="110" sortable :formatter="fixed2"></el-table-column>
                    <el-table-column prop="saleDate" label="卖出日期" width="140" sortable :formatter="dateFormater"></el-table-column>
                    <el-table-column prop="charge" label="收费" width="110" sortable :formatter="fixed2"></el-table-column>
                    <el-table-column prop="profit" label="利润" width="110" sortable :formatter="fixed2"></el-table-column>
                </el-table-column>

            </el-table>
        </el-row>
    </div>
</template>


<script>
import config from '~/config'
import dayjs from '~/plugins/day';

import datadict from '~/plugins/dict';
// import { JSEncrypt } from 'jsencrypt'

export default {
    layout: 'empty',
    data() {
        return {
            tableheight: null,
            stoken: "dac80012011d41a2b8b81ab065328230",
            isLogin : true,
            base:{
                userId: "",
                password: "",
                identifyCode: "",
                randomNum: Math.random(),
            },
            //https://jy.xzsec.com/Login?el=1&clear=&returl=%2fTrade%2fBuy    BaseJs脚本中
            publicKey: "-----BEGIN PUBLIC KEY-----\n" +
                "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDHdsyxT66pDG4p73yope7jxA92\n" +
                "c0AT4qIJ/xtbBcHkFPK77upnsfDTJiVEuQDH+MiMeb+XhCLNKZGp0yaUU6GlxZdp\n" +
                "+nLW8b7Kmijr3iepaDhcbVTsYBWchaWUXauj9Lrhz58/6AE/NF0aMolxIGpsi+ST\n" +
                "2hSHPu3GSXMdhPCkWQIDAQAB\n" +
                "-----END PUBLIC KEY-----",
            tradeList: [],
            hisList: [],
            todayList: [],
            storeList: [],
            storeMap:{},
            revokeList: [],
            detailList: [],
            newStockInfo: null,
            buyHisList: [],
            buyHisMap: {},
            jjList:[
                {name:"中小",code:"110011",rate:""},
                {name:"信息",code:"001513",rate:""}
            ],
            favList:[
                    {c:"300869",n:"康泰医学"},
                    {c:"300318",n:"博晖创新"},
                    {c:"300888",n:"稳健医疗"},
                    {c:"600118",n:"中国卫星"},
                    {c:"002151",n:"北斗星通"},
                    {c:"512670",n:"国防ETF"},
                    // {c:"300878",n:"维康药业"},
                    // {c:"000568",n:"泸州老窖"},
                    // {c:"300181",n:"佐力药业"},
                    // {c:"300122",n:"智飞生物"},
                    {c:"600763",n:"通策医疗"},
                    // {c:"300323",n:"华灿光电"},
                    // {c:"300759",n:"康龙化成"},
                    {c:"603259",n:"药明康得"},
                    {c:"002007",n:"华兰生物"},
                    {c:"002271",n:"东方雨虹"},
                    // {c:"600779",n:"水井坊"},
                    // {c:"002041",n:"登海种业"},
                    // {c:"512290",n:"生物ETF"},
                    // {c:"159995",n:"芯片ETF"},
                    // {c:"600161",n:"天坛生物"},
                    {c:"600519",n:"贵州茅台"},
                    {c:"000799",n:"酒鬼酒"},
                    // {c:"002541",n:"鸿路钢构"},
                    // {c:"300142",n:"沃森生物"},
                    // {c:"300298",n:"三诺生物"},
                    // {c:"600756",n:"浪潮软件"},
                    // {c:"600496",n:"精工钢构"},
                    // {c:"002185",n:"华天科技"},
                    // {c:"600584",n:"长电科技"},
                    // {c:"600536",n:"中国软件"},
                    // {c:"000066",n:"中国长城"},
                    // {c:"000977",n:"浪潮信息"},
                    // {c:"600802",n:"福建水泥"},
                    ],

            //  1. 情人节前买酒店/医药
            //  2. 夏天前夕买啤酒
            //  3. 建军节前军工股
            //  4. 双十一前买直播概念
            stepCfg:{
                    "002541":{base:44.5,step:1.05,stepList:[]},
                    "002945":{top:17.11,step:1.03,stepList:[]},
                    "600536":{top:89.5,step:1.1,stepList:[]},
                    "000066":{top:14.6,step:1.1,stepList:[]},
                    "002185":{top:17.64,step:1.05,stepList:[]},
                    },
            monInfo: {preTotal:100000,total:0,stockVal:0,curLeft:0,realLeft:0,realprofit:0},
            otherMon: 0,
            aotoQry : true,
            tradeInfo:{
                code:"",
                name:"",
                price:0,
                amount:0,
                type:"B",
                detailList:[]
            },
            selData: {},
            sleepTime : 2000,
            redList : [],
        }
    },
     

    mounted() {
        // this.queryHisList();
        var cache = this.getCache();
        if(cache.tradecode) this.tradeInfo.code=cache.tradecode;
        if(cache.stoken) this.stoken=cache.stoken;
        if(cache.userId) this.base.userId=cache.userId;

        for(var key in this.stepCfg){
            this.setStepList(key);
        }

        if(this.tradeInfo.code)
            this.handleSelectionChange({stock:this.tradeInfo.code});
        
    },
    computed: {
        topList(){
            return this.redList;
        }
        // redList:function() {
        //     var list = [];
        //     list = this.detailList.filter(function(item){
        //         if(!item.saleDate){
        //             // item.nextBuy = (item.buyPrice * 0.97).toFixed(2) *1;
        //             if(item.basePrice){
        //                 item.nextSale = (item.basePrice * 1.03).toFixed(2) *1;
        //             }else {
        //                 item.nextSale = (item.buyPrice * 1.03).toFixed(2) *1;
        //             }
        //             return true;
        //         } else{
        //             return false;
        //         } 
        //     })
            
        //     return list;
        // }
    },

    methods: {
        startQuery(is_auto){
            for(var key in this.stepCfg){
                this.setStepList(key);
            }
            // this.queryHisList();
            this.queryTodayList();
            if(is_auto!==true){
                this.setTimer();
                this.queryStoreList();
                this.queryRevokeList();
                this.queryMoneyInfo();
            }
            this.newStockInfo = null;
            this.queryNewStockList();

            // this.test();
        },
        setRedList(){
            var list = [];
            list = this.detailList.filter(function(item){
                if(!item.saleDate){
                    // item.nextBuy = (item.buyPrice * 0.97).toFixed(2) *1;
                    if(item.basePrice){
                        item.nextSale = (item.basePrice * 1.03).toFixed(2) *1;
                    }else {
                        item.nextSale = (item.buyPrice * 1.03).toFixed(2) *1;
                    }
                    return true;
                } else{
                    return false;
                } 
            })
            
            this.redList =  list;
            this.setLastPrice();
        },
        setLastPrice(){
            this.redList.map(item=>{
                if(this.storeMap[item.stock]){
                    item.lastPrice = this.storeMap[item.stock];
                    item.lastRate = this.rateCount(item.lastPrice-item.buyPrice,item.buyPrice)
                }
            });
            this.storeList.map((item)=>{
                var code = item.Zqdm;
                if(this.storeMap[code] && this.storeMap["pre"+code]){
                    var lastprice = this.storeMap[item.Zqdm];
                    var preprice = this.storeMap["pre"+code]
                    item.jryk = (item.Zqsl * (lastprice-preprice)).toFixed(0)*1;
                    item.diff = (lastprice-preprice).toFixed(2)*1;

                    item.wave = this.rateFormat(lastprice-preprice,preprice)

                    item.Ljyk = (item.Zqsl * (lastprice-item.Cbjg)).toFixed(0)*1;
                    item.Ykbl = this.rateFormat(lastprice-item.Cbjg,item.Cbjg)

                    item.Zxjg = lastprice;
                }
            });
            var that = this;
            setTimeout(()=>{
                that.redList.push({});
                that.redList.splice(that.redList.length-1,1);
                that.storeList.push({});
                that.storeList.splice(that.storeList.length-1,1);
            },200);
        },
        getFavPrice(){
            this.favList.map((item)=>{
                this.getDetail(item);
            });
        },

        test() {
            this.$axios.get(`https://jy.xzsec.com/Search/GetStockList?validatekey=`)
            .then((res) => {
            })
        },
        getDetail(item){
            var code = item.c;
            var first = code.substring(0,1);
            if(first=="0" || first=="3" || first=="1"){
                code = "0."+code;
            }else {
                code = "1."+code;
            }
            this.$axios.get(`http://push2.eastmoney.com/api/qt/stock/details/get?fields1=f1,f2,f3,f4&fields2=f51,f52,f53,f54,f55&pos=-61&secid=${code}`)
            .then((res) => {
                if(res.data && res.data.data && res.data.data.details){
                    var datas = res.data.data.details;
                    var prePrice = res.data.data.prePrice;
                    var last = datas[datas.length-1];
                    if(!last) return;
                    var arr = last.split(",");
                    item.p = arr[1];
                    item.r  = this.rateCount(arr[1]-prePrice,prePrice);
                    item.r = item.r.toFixed(2);
                    item.r = item.r*1;
                    this.storeMap[item.c] = arr[1]*1;
                    this.storeMap["pre"+item.c] = prePrice*1;

                    if(item.c == this.tradeInfo.code){
                        datas = datas.reverse();
                        var list = [];
                        datas.map((obj,idx)=>{
                            if(idx>12) return;
                            list.push(obj.split(","));
                        });
                        this.tradeInfo.detailList = list
                    }
                }else{
                    console.error(JSON.stringify(res.data));
                }
            })

            
        },
        reRandom(){
            this.base.randomNum = Math.random();
        },
        clearAll(){
            this.$axios.get(`${config.sapi}/api/dfcf/clearAll`)
            .then((res) => {
                if (res.data.code == 200) {
                    this.$message.success("清除成功");
                    this.isLogin = false;
                } else {
                    this.$message.error(res.data.message);
                }
            })
        },
        encryptedData( data) {
            // 新建JSEncrypt对象
            // let encryptor = new JSEncrypt();
            // 设置公钥
            // encryptor.setPublicKey(this.publicKey);
            // 加密数据
            // return encryptor.encrypt(data);
        },
        setCache(data){
            var json = JSON.stringify(data);
            localStorage.setItem("dfcfCache",json);
        },
        getCache(){
            var data = localStorage.getItem("dfcfCache");
            if(!data) return {};
            return JSON.parse(data);
        },
        keepAlive() {
            var that = this;
            clearInterval(that.keepTimer);
            this.keepTimer = setInterval(()=>{
                that.startQuery(true);
                // that.queryMoneyInfo();
            },60000);

            this.$once('hook:beforeDestroy', () => {            
                clearInterval(that.keepTimer);                                    
            })
            
            
            clearInterval(that.infoTimer);
            this.infoTimer = setInterval(()=>{
                this.getFavPrice()
                this.setLastPrice();
                this.setJJList();
            },2000);

            this.$once('hook:beforeDestroy', () => {            
                clearInterval(that.infoTimer);                                    
            })

            var cache = this.getCache();
            cache.dfcfkey = this.base.key;
            cache.dfcfsessid = this.base.sessid;
            this.setCache(cache);
        },
        setTimer(){
            var that = this;
            clearInterval(that.autoTimer);
            // if(!this.aotoQry) return;
            this.autoTimer = setInterval(()=>{
                if(!that.aotoQry) return;
                if(!that.tradeInfo.code || !that.tradeInfo.code.match(/\d{6}/)) return;
                that.getStep5Price();
                // that.queryStoreList();
            },this.sleepTime);
            this.$once('hook:beforeDestroy', () => {            
                clearInterval(that.autoTimer);                                    
            })
        },
        preCheck(){
            if(!this.stoken){
                this.$message.error("stoken获取失败");
                return false;
            }
            return true;
        },
        handleSelectionChange(row){
            if(row.Zqdm){
                this.tradeInfo.code = row.Zqdm;
            }else if(row.stock){
                this.tradeInfo.code = row.stock;
            }else{
                this.tradeInfo.code = row;
            };
            
            this.tradeInfo.name = "";
            this.tradeInfo.price = 0;
            this.tradeInfo.amount = 0;
            // this.tradeInfo.detailList = [];
            this.getFavPrice();
            this.getStep5Price(true);
            // if(this.stepCfg[this.tradeInfo.code]){
            //     this.setStepList(this.tradeInfo.code);
            // }
        },
        setStepList(code){
            var item = this.stepCfg[code];
            item.stepList=[];
            item.buycount =0;
            if(item.top){
                item.stepList.push(item.top);
                for(var i=0;i<14;i++){
                    var next = (item.stepList[item.stepList.length-1]/item.step).toFixed(2)
                    item.stepList.push(next);
                }
            }else if(item.base){
                item.stepList.push(item.base);
                for(var i=0;i<8;i++){
                   var next = (item.stepList[0]*item.step).toFixed(2);
                    item.stepList.splice(0,0,next);
                }
                for(var i=0;i<6;i++){
                    var next = (item.stepList[item.stepList.length-1]/item.step).toFixed(2)
                    item.stepList.push(next);
                }

            }
        },
        getColor(cur,yes){
            if(cur*1>yes*1){
                return "red";
            }else if(yes*1>cur*1){
                return "green"
            }else {
                return "";
            }
        },
        getRateColor(rate){
            if(rate && rate.replace){
                rate = rate.replace("%","");
            }
            if(rate>0){
                return "red";
            }else if(rate<0){
                return "green"
            }else {
                return "black";
            }
        },
        dateFormater(a,b,c,d){
            if(!c) return "";
            return dayjs(c).format("YYYY-MM-DD HH:mm");
        },
        parseRespData(data){
            if( typeof(data)!=="string") return data;
            var arr = data.split("\n");
            data =  arr[arr.length-1];
            var newdata = {
                code : 200,
                data : JSON.parse(data).Data
            }
            newdata.data = JSON.stringify(newdata.data)
            return newdata;
        },
        setJJList(){
            this.jjList.map((item)=>{
                this.getJJInfo(item)
            });
        },
        getJJInfo(item){
            this.$axios.get(`http://fundgz.1234567.com.cn/js/${item.code}.js?`+Math.random())
            .then((res) => {
                try{
                    res.data = res.data.substring(8,res.data.length-2);
                    res.data = JSON.parse(res.data);
                    item.rate = res.data.gszzl+"%";
                    item.price = res.data.dwjz*1;
                    item.newprice = res.data.gsz*1;
                }catch(ex){

                }
            })
        },
        getStep5Price(is_init_data){
            this.$axios.get(`https://hsmarket.eastmoney.com/api/SHSZQuoteSnapshot?callback=&id=${this.tradeInfo.code}`)
            .then((res) => {
                res.data = res.data.substring(1,res.data.length-2);
                res.data = JSON.parse(res.data);
                if (res.data.status == 0) {
                    this.selData = res.data;
                    this.selData.realtimequote.zt = (this.selData.fivequote.yesClosePrice * 1.10).toFixed(2);
                    this.selData.realtimequote.dt = (this.selData.fivequote.yesClosePrice * 0.9).toFixed(2);

                    if(this.tradeInfo.code.substring(0,1)=="3"){
                        this.selData.realtimequote.zt = (this.selData.fivequote.yesClosePrice * 1.20).toFixed(2);
                        this.selData.realtimequote.dt = (this.selData.fivequote.yesClosePrice * 0.8).toFixed(2);
                    }
                    if(is_init_data || this.tradeInfo.amount==0){
                        this.selPrice(this.selData.realtimequote.currentPrice)
                        
                        var cache = this.getCache();
                        cache.tradecode = this.tradeInfo.code;
                        this.setCache(cache);
                    }
                } else {
                    this.$message.error(res.data.message);
                }
            })
        },
        getStep5Pricebak(is_init_data){
            this.$axios.get(`${config.sapi}/api/dfcf/getStep5Price?code=${this.tradeInfo.code}`)
            .then((res) => {
                if (res.data.code == 200) {
                    this.selData = res.data.data;
                    this.selData.realtimequote.zt = (this.selData.fivequote.yesClosePrice * 1.10).toFixed(2);
                    this.selData.realtimequote.dt = (this.selData.fivequote.yesClosePrice * 0.9).toFixed(2);

                    if(this.tradeInfo.code.substring(0,1)=="3"){
                        this.selData.realtimequote.zt = (this.selData.fivequote.yesClosePrice * 1.20).toFixed(2);
                        this.selData.realtimequote.dt = (this.selData.fivequote.yesClosePrice * 0.8).toFixed(2);
                    }
                    if(is_init_data || this.tradeInfo.amount==0){
                        this.selPrice(this.selData.realtimequote.currentPrice)
                        
                        var cache = this.getCache();
                        cache.tradecode = this.tradeInfo.code;
                        this.setCache(cache);
                    }
                } else {
                    this.$message.error(res.data.message);
                }
            })
        },
        queryMoneyInfo() {
            if(!this.preCheck()) return;
            this.$axios.get(`${config.sapi}/api/dfcf/getMoney?stoken=${this.stoken}`)
            .then((res) => {
                res.data = this.parseRespData(res.data);
                if (res.data.code == 200) {
                    var list = JSON.parse(res.data.data);
                    var item = list[0];
                    this.monInfo.total = parseFloat(item.Zzc);
                    this.keepAlive();
                } else {
                    this.$message.error(res.data.message);
                }
            })
        },
        queryStoreList() {
            if(!this.preCheck()) return;
            this.$axios.get(`${config.sapi}/api/dfcf/getStore?stoken=${this.stoken}`)
            .then((res) => {
                res.data = this.parseRespData(res.data);
                if (res.data.code == 200) {
                    this.storeList = JSON.parse(res.data.data);
                    this.monInfo.stockVal = 0;
                    this.storeList.map((item)=>{
                        item.Ykbl = (item.Ykbl*100).toFixed(2)+"%";
                        this.monInfo.stockVal += item.Zxsz*1;
                        //this.storeMap[""+item.Zqdm] = item.Zxjg *1;
                    });
                } else {
                    this.$message.error(res.data.message);
                }
            })
        },
        queryRevokeList() {
            if(!this.preCheck()) return;
            this.$axios.get(`${config.sapi}/api/dfcf/getRevokeList?stoken=${this.stoken}`)
            .then((res) => {
                res.data = this.parseRespData(res.data);
                if (res.data.code == 200) {
                    this.revokeList = JSON.parse(res.data.data);
                    // this.hisList.map((item)=>{
                    //     item.totalFee = parseFloat(item.Ghf)+ parseFloat(item.Yhs)+ parseFloat(item.Sxf);
                    // });
                } else {
                    this.$message.error(res.data.message);
                }
            })
        },
        queryTodayList() {
            if(!this.preCheck()) return;
            this.$axios.get(`${config.sapi}/api/dfcf/getTodayList?stoken=${this.stoken}`)
            .then((res) => {
                res.data = this.parseRespData(res.data);
                
                if (res.data.code == 200) {
                    var tmplist = JSON.parse(res.data.data);
                    var newList = [];
                    var preitem = null;
                    tmplist.map((item)=>{
                        item.Cjsl = parseFloat(item.Cjsl);
                        item.Cjje = parseFloat(item.Cjje);
                        item.Cjjg = parseFloat(item.Cjjg);
                        //Wtbh
                        if(preitem==null || preitem.Wtbh!=item.Wtbh){
                            newList.push(item);
                            preitem = item;
                        }else if(preitem.Wtbh==item.Wtbh){
                            preitem.Cjsl += item.Cjsl;
                            preitem.Cjje += item.Cjje;
                        }
                    });
                    this.todayList = newList;
                    this.queryHisList();
                } else {
                    this.$message.error(res.data.message);
                }
            })
        },
        queryNewStockList(){
            if(!this.preCheck()) return;
            if(this.newStockInfo) return;
            this.$axios.get(`${config.sapi}/api/dfcf/getNewStockList?stoken=${this.stoken}`)
            .then((res) => {
                res.data = this.parseRespData(res.data);
                if (res.data.code == 200) {
                    this.newStockInfo= res.data.data;
                    this.newStockInfo.list= [];
                    var curdate = dayjs().format("YYYYMMDD");
                    this.newStockInfo.NewStockList.map(item=>{
                        var arr = item.split(",");
                        var date = arr[0];
                        var code = arr[1];
                        var sgType = arr[14];//   -1:申购结束   2:已 购  0:申 购  其他: 待申购
                        if(code.match(/688\d{3}/)) return
                        if(date!=curdate) return;
                        if(sgType!=0) return;
                        this.newStockInfo.list.push(arr);
                    })
                    if(this.newStockInfo.list.length>0){
                        const h = this.$createElement;
                        this.$notify({
                            title: '提示',
                            message: h('i', { style: 'color: red'}, '新股可申购'),
                            duration: 60000
                        });
                    }
                } else {
                    this.$message.error(res.data.message);
                }
            })
        },
        queryHisList() {
            if(!this.preCheck()) return;
            this.$axios.get(`${config.sapi}/api/dfcf/getHisList?stoken=${this.stoken}`)
            .then((res) => {
                res.data = this.parseRespData(res.data);
                if (res.data.code == 200) {
                    this.hisList = JSON.parse(res.data.data);
                    var totalList = [];
                    this.todayList.map((item)=>{
                        item.Cjsl = item.Cjsl*1;
                        item.Cjjg = item.Cjjg*1;
                        item.Cjje = item.Cjje*1;
                        item.date = item.Cjrq+""+item.Cjsj;
                        totalList.push(item);
                    });
                    this.hisList.map((item)=>{
                        item.totalFee = parseFloat(item.Ghf)+ parseFloat(item.Yhs)+ parseFloat(item.Sxf);
                        item.Cjsl = item.Cjsl*1;
                        item.Cjjg = item.Cjjg*1;
                        item.Cjje = item.Cjje*1;
                        item.date = item.Cjrq+""+item.Cjsj;
                        totalList.push(item);
                    });

                    this.tradeList = totalList;
                    this.setDetailList(totalList);
                } else {
                    this.$message.error(res.data.message);
                }
            })
        },
        setDetailList(totalList){
            var that = this;
            this.detailList = [];
            var salelist = [];
            totalList.reverse();
            for(var k = 0 ;k<totalList.length; k++){
                var item = totalList[k];
                if(!this.buyHisMap[item.Zqdm]){
                    this.buyHisMap[item.Zqdm] = item.Zqmc;
                    this.buyHisList.push({value:item.Zqdm,text:item.Zqmc});
                }
                // if(item.Zqdm!="603259") continue;
                if(item.Mmsm.indexOf("买入")!=-1){

                    var amount = this.getUnitAmount(item.Cjjg);
                    if(amount>500 && item.Cjsl%(amount-100)==0){
                        amount = amount-100;
                    }
                    if((item.Cjsl%amount)==0){
                        var num = item.Cjsl/amount;
                        for(var o=0;o<num;o++){
                            this.detailList.push({
                                stock: item.Zqdm,
                                name: item.Zqmc,
                                buyDate: item.date,
                                buyPrice: item.Cjjg,
                                buyAmount: amount,
                                salePrice: 0,
                            });
                        }

                    }else {
                        this.detailList.push({
                            stock: item.Zqdm,
                            name: item.Zqmc,
                            buyDate: item.date,
                            buyPrice: item.Cjjg,
                            buyAmount: item.Cjsl,
                            salePrice: 0,
                        });
                    }
                }else {
                    var tmpitem = null;
                    for (var i =this.detailList.length-1;i >=0;i--){
                        var ritem= this.detailList[i];
                        if(ritem.saleDate || ritem.stock!=item.Zqdm) continue;
                        tmpitem = ritem;
                        var ispresale = false;
                        // for(var m = k+1 ;m<totalList.length; m++){  //会跳走当前元素,
                        //     var mitem= totalList[m];
                        //     if(mitem.Mmsm=="证券买入" && ritem.stock==mitem.Zqdm){
                        //         if(mitem.Cjsl == ritem.buyAmount && mitem.Cjjg*1<item.Cjjg*1){  //先卖出后买入的操作
                        //             debugger;
                        //             mitem.salePrice = item.Cjjg;
                        //             mitem.rate = "";
                        //             mitem.saleDate = item.date;
                        //             mitem.saleTotalPrice = item.total;
                        //             tmpitem = null;
                        //             ispresale = true;
                        //             break;
                        //         }
                        //     }
                        // }
                        if(ispresale ) continue;
                        if(ritem.buyAmount==item.Cjsl){
                            ritem.salePrice = item.Cjjg;
                            ritem.rate = "";
                            ritem.saleDate = item.date;
                            ritem.saleTotalPrice = item.total;
                            tmpitem = null;
                            break;
                        }else if(ritem.buyAmount>item.Cjsl){
                            var newitem={
                                stock: ritem.stock,
                                name: ritem.name,
                                buyDate: ritem.buyDate,
                                buyPrice: ritem.buyPrice,
                                buyAmount: ritem.buyAmount - item.Cjsl,
                                salePrice: 0,
                            }
                            ritem.buyAmount = item.Cjsl;
                            ritem.salePrice = item.Cjjg;
                            ritem.rate = "";
                            ritem.saleDate = item.date;
                            that.detailList.splice(i,0,newitem)
                            tmpitem = null;
                            break;
                        }else {
                            ritem.salePrice = item.Cjjg;
                            ritem.rate = "";
                            ritem.saleDate = item.date;
                            item.Cjsl = item.Cjsl - ritem.buyAmount;
                            //还有剩余数量,继续循环处理
                        }

                    }
                    if(tmpitem!=null){
                        // debugger;
                    }
                }
            }

/*
            for(var i =totalList.length-1;i >=0;i--){
                var item = totalList[i];
                // if(item.Zqdm!="600536") continue;
                if(item.Mmsm=="证券买入"){
                    this.detailList.push({
                        stock: item.Zqdm,
                        name: item.Zqmc,
                        buyDate: item.date,
                        buyPrice: item.Cjjg,
                        buyAmount: item.Cjsl,
                        salePrice: 0,
                    });
                }else {
                    salelist.splice(0,0,item);
                }
            }
            // debugger;
            salelist.map((item)=>{
                // for (var i =0;i < that.detailList.length;i++){
                for (var i =that.detailList.length-1;i >=0;i--){
                    var ritem= that.detailList[i];
                    if(ritem.saleDate || ritem.stock!=item.Zqdm) continue;
                    // if(i==5) debugger;
                    if(ritem.buyDate > item.date) continue;
                    if(ritem.buyAmount==item.Cjsl){
                        ritem.salePrice = item.Cjjg;
                        ritem.rate = "";
                        ritem.saleDate = item.date;
                        ritem.saleTotalPrice = item.total;
                        break;
                    }else if(ritem.buyAmount>item.Cjsl){
                        var newitem={
                            stock: ritem.stock,
                            name: ritem.name,
                            buyDate: ritem.buyDate,
                            buyPrice: ritem.buyPrice,
                            buyAmount: ritem.buyAmount - item.Cjsl,
                            salePrice: 0,
                        }
                        ritem.buyAmount = item.Cjsl;
                        ritem.salePrice = item.Cjjg;
                        ritem.rate = "";
                        ritem.saleDate = item.date;
                        that.detailList.splice(i,0,newitem)
                        break;
                    }else {
                        ritem.salePrice = item.Cjjg;
                        ritem.rate = "";
                        ritem.saleDate = item.date;
                        item.Cjsl = item.Cjsl - ritem.buyAmount;
                        //还有剩余数量,继续循环处理
                    }
                }
            });
            */
            var point = 0.00025;
            that.detailList.map((item)=>{
                item.charge = 0;
                item.buyTotalPrice = item.buyAmount * item.buyPrice;
                item.buyTotalPrice = parseInt(item.buyTotalPrice)
                if(item.buyTotalPrice*point>5){
                    item.charge += item.buyTotalPrice*point;
                }else {
                    item.charge += 5;
                }
                if(!item.saleDate)return;
                item.rate = (item.salePrice - item.buyPrice)*100/item.buyPrice;
                item.saleTotalPrice = item.buyAmount * item.salePrice;
                if(item.saleTotalPrice*point>5){
                    item.charge += item.saleTotalPrice*point;
                }else {
                    item.charge += 5;
                }
                item.charge += item.saleTotalPrice * 0.00104;
                item.profit = item.saleTotalPrice - item.buyTotalPrice - item.charge
            });

            that.detailList.map((item,idx)=>{
                if(item.saleDate) return;
                var stepitem = this.stepCfg[item.stock];
                if(!stepitem) return;
                item.basePrice = stepitem.stepList[stepitem.buycount];
                stepitem.buycount++;
            });
            
            that.detailList.reverse();  

            that.setRedList();
        },
        getSummaries(param) {
            const { columns, data } = param;
            const sums = [];
            var sumarr = ["charge","profit"];
            var pointmap = {profit:1,charge:1};
            var totalinfo = {};
            sumarr.map((item)=>{
                totalinfo[item] = 0;
            })
            
            for(var i=0;i<data.length;i++){
                var row = data[i];
                sumarr.map((item)=>{
                    if(row[item]) totalinfo[item] += row[item];
                })
            }

            columns.forEach((column, index) => {
                if (index === 0) {
                    sums[index] = '合计';
                    return;
                }
                if(sumarr.contains(column.property)){
                    if(pointmap[column.property]){
                        sums[index] = totalinfo[column.property].toFixed(pointmap[column.property]);
                    }else {
                        sums[index] = totalinfo[column.property];
                    }
                    sums[index] = this.bigMoneyFormat(sums[index]);
                }

            });

            return sums;
        },
        revokeOrder(row){
            if(!this.preCheck()) return;
            if(!row) return;
            var order_num = row.Wtrq + "_" + row.Wtbh;
            this.$axios.get(`${config.sapi}/api/dfcf/revokeOrder?stoken=${this.stoken}&order_num=${order_num}`)
            .then((res) => {
                if (res.data.code == 200) {
                    
                } else {
                    this.$message.error(res.data.message);
                }
            })
        },
        getUnitAmount(price){
            var amount = Math.round(10000/(price*100),0)*100;
            if(price>60 && price<90 && amount==100){
                amount = 200;
            }
            return amount;
        },
        buyNewStock(item){
            var code = item[3];
            var name = item[2];
            var amount = item[7]*10000;
            var type = "B";
            var price = item[10];
            this.trade(code,amount,type,price,name);
        },
        tradeStock(code,amount,type,price,name){
            if(!this.preCheck()) return;
            if(!code) return;
            if(type=="S"){
                if(price*amount>20000){
                    amount = this.getUnitAmount(price);
                }
            }else {
                amount = this.getUnitAmount(price);
            }
            this.trade(code,amount,type,price,name);
        },
        priceRate(cur,pre){
            return this.rateFormat(cur-pre,pre)
        },
        selPrice(price){
            if(isNaN(price)) return;
            this.tradeInfo.price = price*1;
            this.tradeInfo.amount = this.getUnitAmount(price);
        },
        goTrade(){
            if(!this.tradeInfo.code || !this.tradeInfo.amount || !this.selData.name || !this.tradeInfo.price){
                this.$message.error("表单不完整");
                return;
            }
            this.trade(this.tradeInfo.code,this.tradeInfo.amount,this.tradeInfo.type,this.tradeInfo.price,this.selData.name);
        },
        trade(code,amount,type,price,name){
            
            var oper = "买入";
            if(type=="S"){
                oper ="卖出";
            }
            this.$confirm(`${price}元/股${oper}${code}${name}${amount}股(总额:${price*amount})?`, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.$axios.get(`${config.sapi}/api/dfcf/trade?stoken=${this.stoken}&code=${code}&amount=${amount}&type=${type}&price=${price}`)
                .then((res) => {
                    if (res.data.code == 200) {
                        this.$message.success("交易成功");
                    } else {
                        this.$message.error(res.data.message);
                    }
                })
            })
        },
        getRowClass(scope){
            if(scope.row.stock==this.tradeInfo.code){
                return "tips-blue";
            }
            return ""
        },
        filterDetailList(value, row, column){
            return row.stock === value;
        },
        openLoginPage(){
            window.open("https://jy.xzsec.com/Login");
        },
        openInfoPage(){
            var pageList = ["https://jy.xzsec.com/Search/Position",
                "https://jy.xzsec.com/Trade/Revoke",
                "https://jy.xzsec.com/Search/Deal",
                "https://jy.xzsec.com/Search/HisDeal",
                "https://jy.xzsec.com/Trade/NewBuy",
                "https://jy.xzsec.com/Trade/Sale",
                ];

            setInterval(function(){
                if(pageList.length>0){
                    window.open(pageList[0]);
                    pageList.splice(0,1)
                }
            },2000);
            
        }
    }
}
</script>

<style lang="less" scoped>
.block-item{
     border:1px lightgray dotted;
     margin:5px 20px;
     padding:10px;
}
.flexdiv {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 10px;
    button{
        margin-left: 10px;
    }
}
.ml20 {
    margin-left: 20px;
}

.qryform{
    margin-bottom:10px;
    button{
        margin-top:0px;
        vertical-align: middle;
    }
}
.order-class{
    display: inline-block;
    margin-right: 10px;
    min-width: 50px;
}

.red{
    color: red;
}
.green{
    color: green;
}
.black{
    color: black;
}
.yellow{
    color: rgb(96, 22, 233)
}
.link-item{
    font-size: 12px;
}

.span-name{
    display: inline-block;
    width: 60px;
    text-align: center;
}
.span-price{
    display: inline-block;
    width: 60px;
    text-align: center;
}
.span-rate{
    display: inline-block;
    width: 40px;
    text-align: right;
}

</style>
